package models;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.UniqueConstraint;

import play.data.validation.Constraints.Pattern;
import play.data.validation.Constraints.Required;
import play.db.ebean.Model;

@Entity
@Table(name = "companies", uniqueConstraints = @UniqueConstraint(columnNames = "company_id"))
public class Company extends Model {

	private static final long serialVersionUID = 1L;

	@Column(name = "id")
	@GeneratedValue(generator = "SEQ_TABLE", strategy = GenerationType.TABLE)
	@Id
	@TableGenerator(name = "SEQ_TABLE")
	private long id;
	
	@Column(name = "name")
	@Pattern(value = "[A-Za-z0-9\\-_][A-Za-z0-9\\-_ ]+", message = "The name contains invalid characters. Valid characters are: A-Z, 0-9, hyphen (-), underscore (_) and white space ( ).")
	@Required
	private String name;
	
	@Column(name = "company_id")
	private String companyId;
	
	@Column(name = "country_code")
	@Pattern(value = "[A-Za-z]{2}", message="The country code invalid characters or is not exactly 2 characters, valid characters are: A-Z")
	@Required
	private String countryCode;
	
	@Column(name = "created")
	private Date created;
	
	@Column(name = "last_modified")
	private Date lastModified;

	public static final Finder<Long, Company> find = new Finder<Long, Company>(long.class, Company.class);

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCompanyId() {
		return companyId;
	}

	public void setCompanyId(String companyId) {
		this.companyId = companyId;
	}

	public String getCountryCode() {
		return countryCode;
	}

	public void setCountryCode(String countryCode) {
		this.countryCode = countryCode;
	}

	public Date getCreatedDate() {
		return created;
	}

	public void setCreatedDate(Date created) {
		this.created = created;
	}

	public Date getLastModifiedDate() {
		return lastModified;
	}

	public void setLastModifiedDate(Date lastModified) {
		this.lastModified = lastModified;
	}

	@Override
	public String toString() {
		return "Company [id=" + id + ", name=" + name + ", companyId=" + companyId + ", countryCode=" + countryCode + ", created=" + created + ", lastModified=" + lastModified + "]";
	}

}
